//
//  TableViewViewController.m
//  TableView
//
//  Created by iMac-hxsd on 12-2-26.
//  Copyright 2012年 __MyCompanyName__. All rights reserved.
//

#import "TableViewViewController.h"
#import "EmailViewController.h"

@implementation TableViewViewController

@synthesize tableIndexData;

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    self.tableIndexData = [[NSArray alloc] initWithObjects:@"收件箱", @"草稿", @"已发送", @"废纸篓", nil];

    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}

#pragma mark - Table View Methods

// 表格数据行数
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.tableIndexData count];
}

// 表格数据
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *tableIdentifier = @"tableIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableIdentifier];

    if(cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithFrame:CGRectZero];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    cell.textLabel.text = [self.tableIndexData objectAtIndex:[indexPath row]];

    UIImage *image = [UIImage imageNamed:@"email.png"];
    cell.imageView.image = image;

    return cell;
}

- (void) tableView : (UITableView *) aTableView didSelectRowAtIndexPath : (NSIndexPath *) indexPath
{
    EmailViewController *emailViewController = [[EmailViewController alloc] initWithNibName:@"EmailViewController" bundle:nil];
    [self.navigationController pushViewController:emailViewController animated:YES];
}

@end
